import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;


public class HelpDialog extends JDialog {

	public HelpDialog(JFrame f) {
		super(f);
		buildDialog();
		//setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				closeSelf();
			}
		});

		setTitle("Help");
		setSize(320,480);
		setLocationRelativeTo(null);
		setVisible(true);

	}

	protected void closeSelf() {
		// TODO Auto-generated method stub
		GuiderFrame.isOpenHelp = false;
		dispose();
	}

	private void buildDialog() {
		BufferedReader br = null;
		File f = new File("help.txt");
		String helpText="";
		
		try {
			br = new BufferedReader(new FileReader(f));
			String s=br.readLine();
			while(s!=null){
				if (helpText.length()>0) helpText+="\n";
				helpText+=s;
				s=br.readLine();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		JTextArea help = new JTextArea(helpText, GuiderFrame.TXA_ROWS, GuiderFrame.TXA_COLUMNS);
		help.setEditable(false);
		help.setLineWrap(true);
		JScrollPane sp = new JScrollPane(help);

		JButton btnOk = new JButton("OK");
		btnOk.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				closeSelf();
			}
		});	
		JPanel pnldown = new JPanel(new FlowLayout());
		pnldown.add(btnOk);
		Container cntr = getContentPane();
		cntr.setLayout(new BorderLayout());
		cntr.add(sp, BorderLayout.CENTER);
		cntr.add(pnldown, BorderLayout.SOUTH);
		
	}

}
